<!--正在检测信息显示页面-->
<!--检测任务具体信息-->
<template>
	<view>
		<view class="test-time">
			已检测{{index}}秒
		</view>
		<view class="exame-value">
			<span>检测值：</span>
			<input v-model="examValue" :maxlength="100"
				style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
				placeholder="请输入检测值" />
		</view>
		<!-- <view class="current-value">
		最大值：{{examedCount}}
		</view> -->
		<view class="fire-button">
			<button type="primary" class="mini-btn" @tap="startFire">点火</button>
		</view>
		<view class="test-operation-button">
			<button type="primary" class="mini-btn" @tap="confirmData">确定</button>
			<button type="primary" class="mini-btn" @tap="reTesting">重新检测</button>
			<button type="primary" class="mini-btn" @tap="goBack">返回</button>
		</view>
	</view>


</template>

<script setup>
	import {
		ref,
		onMounted,
		onDeactivated
	} from "vue"
	import {
		onLoad,
	} from "@dcloudio/uni-app";
	import {
		batchInsertExam,positionStart,positionAdd
	} from '@/api/deviceTest.js';
	const timer = ref(0)
	const index = ref(0)
	const examValue = ref('')
	const testInfo = ref({})
	const backValue = ref('')
	const parentId = ref('')
	onLoad((option) => {
		if (option) {
			//console.log("optionoption",option.info);
			//console.log("optionoption111",JSON.parse(JSON.stringify(option.info)));
			testInfo.value = JSON.parse(option.info);
		}
	});
	onMounted(() => {
		timer.value = window.setInterval(function logname() {
			index.value = index.value + 1
		}, 1000);
		backValue.value = uni.getStorageSync('backValue');
		getLocationData();
	})
	onDeactivated(() => { //离开当前组件的生命周期执行的方法
		window.clearInterval(timer.value);
	})
	const getNowTime = () => {
		const now = new Date();
		const year = now.getFullYear();
		const month = ('0' + (now.getMonth() + 1)).slice(-2);
		const day = ('0' + now.getDate()).slice(-2);
		const hours = ('0' + now.getHours()).slice(-2);
		const minutes = ('0' + now.getMinutes()).slice(-2);
		const seconds = ('0' + now.getSeconds()).slice(-2);

		const formattedTime = year + '-' + month + '-' + day +
			' ' + (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (
				seconds < 10 ? '0' + seconds : seconds)
        console.log("formattedTime",formattedTime);
		return formattedTime
	}
	//点火
	const startFire = () => {}
	//确定
	const confirmData = () => {
		//console.log("00000",JSON.parse(testInfo.value));
		let tempObject = {};
		tempObject.examValue = examValue.value - backValue.value;
		console.log("11111",tempObject.examValue);
		//console.log("2222",tempObject.leakMax);
		if (tempObject.examValue < tempObject.leakMax) {
			tempObject.isLeak = "是"
		} else {
			tempObject.isLeak = "否"
		}
		tempObject.examValue = tempObject.examValue + '';
		tempObject.pointFullNo = JSON.parse(testInfo.value).pointFullNo;
		tempObject.pointOnlyNo = JSON.parse(testInfo.value).pointOnlyNo;
		tempObject.type = JSON.parse(testInfo.value).type;
		tempObject.materialStatus = JSON.parse(testInfo.value).materialStatus;
		tempObject.year = JSON.parse(testInfo.value).year;
		tempObject.season = JSON.parse(testInfo.value).season;
		tempObject.examTime = getNowTime();
		tempObject.examUser = uni.getStorageSync('user').userName;
		tempObject.deviceType = uni.getStorageSync('deviceType');
		tempObject.deviceNo = uni.getStorageSync('deviceNo');
		tempObject.deviceValue = JSON.parse(testInfo.value).deviceValue;
		tempObject.responseFactor = JSON.parse(testInfo.value).responseFactor;
		tempObject.backValue = uni.getStorageSync('backValue');
		//tempObject.examValue = JSON.parse(testInfo.value).examValue;
		let dataList = [];
		dataList.push(tempObject);
		let params = {
			factoryId: uni.getStorageSync('factoryId'),
			examList: JSON.stringify(dataList),
			year: uni.getStorageSync('year'),
			season: uni.getStorageSync('season'),
		};
		//console.log('ppppppp', params)
		batchInsertExam(params).then(res => {
			console.log("ressss", res);
			//上传成功之后，将storage中的task清空
			// if(){
			// 	uni.clearStorageSync("calibrationManagementList")
			// }
		})
	}
	//重新检测
	const reTesting = () => {}
	//返回
	const goBack = () => {}
	//开始定位
	const startPosition = () =>{
	let params = {
		taskId:uni.getStorageSync('taskId'),
		factoryId: uni.getStorageSync('factoryId'),
		posX:"",
		posY:"",
		posAdress:""
	};	
	// positionStart(params).then(res => {
	// 		console.log("ddddddd", res);
	// 	})
	//parentId
	}
	//更新定位
	const updatePosition=()=>{
		let params = {
			taskId:uni.getStorageSync('taskId'),
			factoryId: uni.getStorageSync('factoryId'),
			posX:"",
			posY:"",
			posAdress:"",
			parentId:""
		};	
		// positionAdd(params).then(res => {
		// 		console.log("AAAAAAA", res);
		// 	})
	}
	//获取坐标
	const  getLocationData = ()=>{
	uni.getLocation({
		type: 'wgs84',
		success: function (res) {
			console.log("当前位置信息",res);
			console.log('当前位置的经度：' + res.longitude);
			console.log('当前位置的纬度：' + res.latitude);
		}
	});

	}
</script>

<style scoped lang="scss">
	.test-time {
		width: 100%;
		height: 200rpx;
		text-align: center;
		line-height: 200rpx;
	}

	.exame-value {
		margin-top: 200rpx;
		width: 100%;
		//height:300rpx;
		text-align: center;
		//line-height: 300rpx;
		display: flex;
		flex-direction: row;
		padding-left: 20%;
	}

	.fire-button {
		text-align: center;
		margin-top: 500rpx;
		width: 200rpx;
		padding-left: 35%;
	}

	.test-operation-button {
		position: fixed;
		bottom: 10rpx;
		left: 0;
		width: 100%;
		padding: 25rpx 82rpx;
		background: white;
		z-index: 2;
		box-sizing: border-box;
		padding: 20rpx 30rpx;
		background: rgba(255, 255, 255, 0.6);
		display: flex;
		flex-direction: row;

		uni-button {
			line-height: 100rpx !important;
			font-size: 30rpx;
		}
	}
</style>